<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<script>
			// 箭头函数的this是如何查找的？
			// 向外层作用域中,一层一层查找this,直到有this的定义			
			const obj = {
				fn() {
					setTimeout(function() {
						console.log(this) //window
					});
					setTimeout(() => {
						console.log(this)
					}) //obj对象
				}
			}
			obj.fn();

			const obj2 = {
				fn() {
					setTimeout(function() {
						setTimeout(function() {
							console.log(this) //window
						});
						setTimeout(() => {
							console.log(this)
						}) //window
					});
					setTimeout(() => {
						setTimeout(function() {
							console.log(this) //window
						});
						setTimeout(() => {
							console.log(this)
						}) //obj2对象
					})
				}
			}
			obj2.fn()
		</script>
	</body>
</html>
